package com.example.exp03_calculatebmi.data;

import java.io.Serializable;
import java.text.DecimalFormat;

/**
 * No Serializable（可以调优！）
 * 最好要使用安卓的序列化技术
 * 这样会更安全一些！
 */
public class Adult implements Serializable {
    public  static DecimalFormat df = new DecimalFormat( "0.00"); //设置Double类型小数点后位数格式
    private String gender;

    @Override
    public String toString() {
        return "Adult{" +
                "gender='" + gender + '\'' +
                ", height=" + height +
                ", weight=" + weight +
                ", bmi=" + bmi +
                '}';
    }

    private Double height; //这里的身高初始化为单位为米的数值
    private Double weight;

    private Double bmi;

    public Adult() {
    }

    public Adult(String gender, Double height, Double weight) {
        this.gender = gender;
        this.height = height/100;
        this.weight = weight;
        this.bmi = this.weight/(this.height*this.height);
    }

    public Double getBmi() {
        return bmi;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Double getHeight() {
        return height;
    }

    public void setHeight(Double height) {
        this.height = height;
    }

    public Double getWeight() {
        return weight;
    }

    public void setWeight(Double weight) {
        this.weight = weight;
    }

    public String judge(){
        String ans = "";
        String healthyWeightLow = "";
        String healthyWeightHigh = "";
        Integer level = 0;
        if (this.gender.equals("男")){
            healthyWeightLow = df.format(20.7*this.height*this.height);
            healthyWeightHigh = df.format(26.4*this.height*this.height);
            if (bmi < 17.5){
                level = HealthLevel.ANOREXIA;
            } else if (bmi < 20.7) {
                level = HealthLevel.UNDERWEIGHT;
            }else if (bmi <= 26.4) {
                level = HealthLevel.HEALTHY;
            }else if (bmi <= 27.8) {
                level = HealthLevel.LIGHTLYOVERWEIGHT;
            }else {
                level = HealthLevel.OVERWEIGHT;
            }
        }else if (this.gender.equals("女")){
            healthyWeightLow = df.format(19.1*this.height*this.height);
            healthyWeightHigh = df.format(25.8*this.height*this.height);
            if (bmi < 17.5){
                level = HealthLevel.ANOREXIA;
            } else if (bmi < 19.1) {
                level = HealthLevel.UNDERWEIGHT;
            }else if (bmi <= 25.8) {
                level = HealthLevel.HEALTHY;
            }else if (bmi <= 27.3) {
                level = HealthLevel.LIGHTLYOVERWEIGHT;
            }else {
                level = HealthLevel.OVERWEIGHT;
            }

        }

        if (level.equals(HealthLevel.ANOREXIA)){
            ans = "您的合适的体重范围为" + healthyWeightLow + "~" + healthyWeightHigh +"kg\n"
                    + "身体质量指数为" + df.format(this.bmi) + "，属于厌食的范围，\n"
                    + "请及时就医咨询！";
        } else if (level.equals(HealthLevel.UNDERWEIGHT)) {
            ans = "您的合适的体重范围为" + healthyWeightLow + "~" + healthyWeightHigh +"kg\n"
                    + "身体质量指数为" + df.format(this.bmi) + "，属于体重偏轻的范围，\n"
                    + "请注意多摄入营养！";
        }else if (level.equals(HealthLevel.HEALTHY)) {
            ans = "您的合适的体重范围为" + healthyWeightLow + "~" + healthyWeightHigh +"kg\n"
                    + "身体质量指数为" + df.format(this.bmi) + "，属于正常范围，\n"
                    + "请继续保持！";
        }else if (level.equals(HealthLevel.LIGHTLYOVERWEIGHT)) {
            ans = "您的合适的体重范围为" + healthyWeightLow + "~" + healthyWeightHigh +"kg\n"
                    + "身体质量指数为" + df.format(this.bmi) + "，属于略微超重范围，\n"
                    + "请注意饮食和运动！";
        }else if (level.equals(HealthLevel.OVERWEIGHT)) {
            ans = "您的合适的体重范围为" + healthyWeightLow + "~" + healthyWeightHigh +"kg\n"
                    + "身体质量指数为" + df.format(this.bmi) + "，属于超重范围，\n"
                    + "请注意改善饮食结构和增加运动量！";
        }
        return ans;
    }
}
